-
Notifications
You must be signed in to change notification settings - Fork 421
fix(feature_flags): handle expected falsy values in conditions #2052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nnot have Falsy values
…nnot have Falsy values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, thanks for the additional tests!
Only a minor semantic correction, pushing from GitHub UI so we can make a patch release.
hmmm, GitHub review is messing up indentation and isn't signing off commit to push the change. Can't push to your fork either - here's the patch with the changes whenever you can. From bd8a6215e4815cc729d0c695d42a14144bc56ee7 Mon Sep 17 00:00:00 2001
From: heitorlessa <[email protected]>
Date: Mon, 27 Mar 2023 14:26:08 +0200
Subject: [PATCH] chore: use null instead of none in err msg
---
aws_lambda_powertools/utilities/feature_flags/schema.py | 2 +-
tests/functional/feature_flags/test_schema_validation.py | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/aws_lambda_powertools/utilities/feature_flags/schema.py b/aws_lambda_powertools/utilities/feature_flags/schema.py
index df999a51..08f2ee13 100644
--- a/aws_lambda_powertools/utilities/feature_flags/schema.py
+++ b/aws_lambda_powertools/utilities/feature_flags/schema.py
@@ -327,7 +327,7 @@ class ConditionsValidator(BaseValidator):
def validate_condition_value(condition: Dict[str, Any], rule_name: str):
value = condition.get(CONDITION_VALUE)
if value is None:
- raise SchemaValidationError(f"'value' key must not be none, rule={rule_name}")
+ raise SchemaValidationError(f"'value' key must not be null, rule={rule_name}")
action = condition.get(CONDITION_ACTION, "")
# time actions need to be parsed to make sure date and time format is valid and timezone is recognized
diff --git a/tests/functional/feature_flags/test_schema_validation.py b/tests/functional/feature_flags/test_schema_validation.py
index 8441b944..8d3b97ad 100644
--- a/tests/functional/feature_flags/test_schema_validation.py
+++ b/tests/functional/feature_flags/test_schema_validation.py
@@ -301,7 +301,7 @@ def test_validate_condition_missing_condition_value():
}
# WHEN calling validate_condition
- with pytest.raises(SchemaValidationError, match="'value' key must not be none"):
+ with pytest.raises(SchemaValidationError, match="'value' key must not be null"):
ConditionsValidator.validate_condition_value(condition=condition, rule_name="dummy")
@@ -314,7 +314,7 @@ def test_validate_condition_none_condition_value():
}
# WHEN calling validate_condition
- with pytest.raises(SchemaValidationError, match="'value' key must not be none"):
+ with pytest.raises(SchemaValidationError, match="'value' key must not be null"):
ConditionsValidator.validate_condition_value(condition=condition, rule_name="dummy")
--
2.37.1 (Apple Git-137.1) |
hmmm, GitHub review is messing up indentation and isn't signing off commit to push the change. Can't push to your fork either - here's the git patch with the changes whenever you can. From bd8a6215e4815cc729d0c695d42a14144bc56ee7 Mon Sep 17 00:00:00 2001
From: heitorlessa <[email protected]>
Date: Mon, 27 Mar 2023 14:26:08 +0200
Subject: [PATCH] chore: use null instead of none in err msg
---
aws_lambda_powertools/utilities/feature_flags/schema.py | 2 +-
tests/functional/feature_flags/test_schema_validation.py | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/aws_lambda_powertools/utilities/feature_flags/schema.py b/aws_lambda_powertools/utilities/feature_flags/schema.py
index df999a51..08f2ee13 100644
--- a/aws_lambda_powertools/utilities/feature_flags/schema.py
+++ b/aws_lambda_powertools/utilities/feature_flags/schema.py
@@ -327,7 +327,7 @@ class ConditionsValidator(BaseValidator):
def validate_condition_value(condition: Dict[str, Any], rule_name: str):
value = condition.get(CONDITION_VALUE)
if value is None:
- raise SchemaValidationError(f"'value' key must not be none, rule={rule_name}")
+ raise SchemaValidationError(f"'value' key must not be null, rule={rule_name}")
action = condition.get(CONDITION_ACTION, "")
# time actions need to be parsed to make sure date and time format is valid and timezone is recognized
diff --git a/tests/functional/feature_flags/test_schema_validation.py b/tests/functional/feature_flags/test_schema_validation.py
index 8441b944..8d3b97ad 100644
--- a/tests/functional/feature_flags/test_schema_validation.py
+++ b/tests/functional/feature_flags/test_schema_validation.py
@@ -301,7 +301,7 @@ def test_validate_condition_missing_condition_value():
}
# WHEN calling validate_condition
- with pytest.raises(SchemaValidationError, match="'value' key must not be none"):
+ with pytest.raises(SchemaValidationError, match="'value' key must not be null"):
ConditionsValidator.validate_condition_value(condition=condition, rule_name="dummy")
@@ -314,7 +314,7 @@ def test_validate_condition_none_condition_value():
}
# WHEN calling validate_condition
- with pytest.raises(SchemaValidationError, match="'value' key must not be none"):
+ with pytest.raises(SchemaValidationError, match="'value' key must not be null"):
ConditionsValidator.validate_condition_value(condition=condition, rule_name="dummy")
--
2.37.1 (Apple Git-137.1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few tests that need fix - the expected value is the same as non-expected value which means that these tests will never fail
- test_flags_not_equal_match
- test_flags_less_than_match
- test_flags_less_than_or_equal_match_1
- test_flags_less_than_or_equal_match_2
- test_flags_greater_than_match
- test_flags_greater_than_or_equal_match_1
- test_flags_greater_than_or_equal_match_2
Apart from these the sample test case in the documentation also has the same flaw.
I'll be happy to raise a separate PR for this but since fixing one of these tests would have failed if did not have the flaw, I thought we can ship these together under common context. Let me know your thoughts
@ajwad-shaikh had an idea now that GitHub seems to be back -- create a new PR (I'm merging this shortly), so we can make sure you're credited properly in your first contribution <3 |
Signed-off-by: Heitor Lessa <[email protected]>
Signed-off-by: Heitor Lessa <[email protected]>
Signed-off-by: Heitor Lessa <[email protected]>
For future reference until we manage to create issues for these, two things I'd love to do/get help in Feature Flags:
|
Pinged you on Discord, I'll wait for the separate PR before we make a release. If you get busy, we'll create one by EOW and credit accordingly either way... but I'd really love to make sure you get your experience in making your first contribution ;) Merging - thanks again @ran-isenberg ! |
Issue number: #2051
Summary
Rule Conditions allow users to evaluate context attributes against values and actions defined in Rule Conditions.
The condition can easily be pivoted on a certain value in the context evaluating to falsy values
The values attribute should be able to accept any value except null
The condition should also honor any value for context key variable.
Changes
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
RFC issue number:
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.